package com.lj.back.manage.scaffold.common.exception;

import com.lj.back.manage.scaffold.common.util.ResponseConstant;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 自定义异常
 * @author lv
 * @version 1.0.0
 */
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR,reason = "发生自定义异常")
public class MyException extends RuntimeException{

    /**
     * 状态码  默认为500
     */
    private int code = ResponseConstant.CODE_ERROR;

    /**
     * 描述信息
     */
    private String message = ResponseConstant.MESSAGE_ERROR;

    /**
     * 无参构造
     */
    public MyException(){}

    /**
     * 带描述信息的有参构造
     * @param message 描述信息
     */
    public MyException(String message){
        this.message = message;
    }

    /**
     * 设置描述信息
      * @param message 描述信息
     * @return 当前对象
     */
    public MyException message(String message){
        this.message = message;
        return this;
    }

    /**
     * 设置状态码
     * @param code 状态码
     * @return 当前对象
     */
    public MyException code(int code){
        this.code = code;
        return this;
    }
}
